package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/menu")
public class menuController {
    @Reference
    MenuService menuService;
   /*新增功能*/
    @RequestMapping("/add")
    public Result add(@RequestBody Menu menu){
        menuService.add(menu);
        return new Result(true,"菜单新增成功");
    }
    @RequestMapping("findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = menuService.findByPage(queryPageBean);
        return new Result(true,"菜单管理分页成功",pageResult);
    }
    @RequestMapping("/delById")
    public Result delById(Integer id){

            menuService.delById(id);

        return new Result(true,"菜单管理删除成功");

    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
     Menu menu = menuService.findById(id);
     return new Result(true,"编辑回显成功",menu);
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Menu menu){
        menuService.edit(menu);
        log.debug("findById + menu" + menu);
        return new Result(true,"编辑修改信息成功");
    }
}
